package com.csii.adhoc.JdbcTemplate;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class JDBConfig {
    //定义一个yml配置文件里的静态变量
    @Value("${spring.datasource.url}")
    private  String url;

    @Value("${spring.datasource.driver-class-name}")
    private  String driverClassName;

    @Value("${spring.datasource.username}")
    private  String userName;

    @Value("${spring.datasource.password}")
    private  String password;

    public static String JDBC_URL;
    public static String JDBC_DRIVER_CLASS_NAME;
    public static String JDBC_USER_NAME;
    public static String JDBC_PASSWORD;

    //利用@PostConstruct将yml中配置的值赋给本地的变量
    @PostConstruct
    public void getUrl() {
        JDBC_URL=this.url;
    }

    @PostConstruct
    public void getDriverClassName() {
        JDBC_DRIVER_CLASS_NAME=this.driverClassName;
    }

    @PostConstruct
    public void getUserName() {
        JDBC_USER_NAME=this.userName;
    }

    @PostConstruct
    public void getPassword() {
        JDBC_PASSWORD=this.password;
    }
}
